package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.sales.domain.NcDistributionPlan;
import com.lxmes.sales.service.INcDistributionPlanService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 配送计划Controller
 *
 * @author lx
 * @date 2023-04-21
 */
@Api(tags = "配送计划")
@RestController
@RequestMapping("/business/ncDistributionPlan")
public class NcDistributionPlanController extends BaseController
{
    @Autowired
    private INcDistributionPlanService ncDistributionPlanService;

    /**
     * 查询配送计划列表
     */
    @ApiOperation("查询配送计划列表")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcDistributionPlan ncDistributionPlan)
    {
        startPage();
        List<NcDistributionPlan> list = ncDistributionPlanService.selectNcDistributionPlanList(ncDistributionPlan);
        return getDataTable(list);
    }

    /**
     * 导出配送计划列表
     */
    @ApiOperation("导出配送计划列表")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:export')")
    @Log(title = "配送计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcDistributionPlan ncDistributionPlan)
    {
        List<NcDistributionPlan> list = ncDistributionPlanService.selectNcDistributionPlanList(ncDistributionPlan);
        ExcelUtil<NcDistributionPlan> util = new ExcelUtil<NcDistributionPlan>(NcDistributionPlan.class);
        util.exportExcel(response, list, "配送计划数据");
    }

    /**
     * 获取配送计划详细信息
     */
    @ApiOperation("获取配送计划详细信息")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncDistributionPlanService.selectNcDistributionPlanById(id));
    }

    /**
     * 新增配送计划
     */
    @ApiOperation("新增配送计划")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:add')")
    @Log(title = "配送计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcDistributionPlan ncDistributionPlan)
    {
        return toAjax(ncDistributionPlanService.insertNcDistributionPlan(ncDistributionPlan));
    }

    /**
     * 修改配送计划
     */
    @ApiOperation("修改配送计划")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:edit')")
    @Log(title = "配送计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcDistributionPlan ncDistributionPlan)
    {
        return toAjax(ncDistributionPlanService.updateNcDistributionPlan(ncDistributionPlan));
    }

    /**
     * 删除配送计划
     */
    @ApiOperation("删除配送计划")
    @PreAuthorize("@ss.hasPermi('business:ncDistributionPlan:remove')")
    @Log(title = "配送计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncDistributionPlanService.deleteNcDistributionPlanByIds(ids));
    }
    /**
     * 导入配送计划
     */
    @Log(title = "配送计划", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcDistributionPlan> util = new ExcelUtil<>(NcDistributionPlan.class);
        List<NcDistributionPlan> ncDistributionPlanList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncDistributionPlanService.imporIteminfo(ncDistributionPlanList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcDistributionPlan> util = new ExcelUtil<>(NcDistributionPlan.class);
        util.importTemplateExcel(response,"配送计划");
    }
}
